// Copyright (C) 2025 Focus Media Holding Ltd. All Rights Reserved.

package cn.pacerx.running.wx.web;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

import cn.pacerx.running.wx.dto.JoinActivityDto;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.pacerx.running.wx.dto.ActivityDto;
import cn.pacerx.running.wx.service.ActivityService;
import cn.pacerx.running.wx.service.UserActivityService;
import cn.pacerx.running.wx.vo.ActivityPagedVo;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;

/**
 * ActivityController
 *
 * @author zhanglingwei@focusmedia.cn
 * @since 2025-06-08
 */
@RestController
@RequestMapping("/wx/activity")
@Validated
@RequiredArgsConstructor
public class ActivityController {
    private final ActivityService activityService;
    private final UserActivityService userActivityService;

    /**
     * 活动列表
     */
    @PostMapping("/list")
    @ApiOperation(value = "活动列表")
    public Object list(@Valid @RequestBody ActivityPagedVo pageQueryVo) {
        return activityService.getPagedList(pageQueryVo);
    }

    /**
     * 活动详情
     *
     * @param id 活动ID
     * @return 活动详情
     */
    @GetMapping("/detail")
    @ApiOperation(value = "活动明细")
    public Object detail(@NotNull @RequestParam("id") Long id) {
        return activityService.getById(id);
    }

    /**
     * 添加或更新活动
     *
     * @param activityDto 活动
     * @return 添加或更新操作结果
     */
    @PostMapping("save")
    @ApiOperation(value = "新增or保存活动")
    public Object save(@RequestBody @Valid ActivityDto activityDto) {
        return activityService.save(activityDto);
    }

    /**
     * 删除活动
     *
     * @param id 用户活动id
     * @return 删除操作结果
     */
    @PostMapping("/delete/{id}")
    @ApiOperation(value = "删除活动")
    public Object delete(@PathVariable("id") @NotNull Long id) {
        return activityService.delete(id);
    }

    /**
     * 报名活动
     *
     * @param joinActivityDto 活动报名信息
     * @return 报名操作结果
     */
    @PostMapping("/join")
    @ApiOperation(value = "报名活动")
    public Object join(@Valid @RequestBody JoinActivityDto joinActivityDto) {
        return userActivityService.save(joinActivityDto);
    }

    /**
     * 退出报名活动
     *
     * @param id 活动id
     * @return 操作结果
     */
    @PostMapping("/exit/{id}")
    @ApiOperation(value = "退出报名活动")
    public Object exit(@PathVariable("id") @NotNull Long id) {
        return userActivityService.delete(id);
    }

    @PostMapping("/list/mine")
    @ApiOperation(value = "我的活动列表")
    public Object mimeList(@Valid @RequestBody ActivityPagedVo pageQueryVo) {
        return activityService.getMinePagedList(pageQueryVo);
    }

}
